package com.piece.core.log.support;

import com.piece.core.log.client.dto.AuditLogDTO;
import com.piece.core.log.client.dto.BeanPostLogDTO;
import com.piece.core.log.client.dto.LoginLogDTO;
import com.piece.core.log.client.dto.MessageLogDTO;
import com.piece.core.log.config.RequestContextHolder;
import com.piece.core.log.config.TenantContextHolder;
import com.piece.core.log.config.UserContextHolder;
import java.util.Date;

public class LogUtil {

    public static AuditLogDTO buildAuditLog(String applicationName) {
        return AuditLogDTO.builder()
                .applicationName(applicationName)
                .clientId(TenantContextHolder.getTenant())
                .operaId(UserContextHolder.getUserId())
                .operaName(UserContextHolder.getUserName())
                .ip(RequestContextHolder.get().getIp())
                .city(RequestContextHolder.get().getCity())
                .area(RequestContextHolder.get().getArea())
                .os(RequestContextHolder.get().getOs())
                .browser(RequestContextHolder.get().getBrowser())
                .status("0")
                .operaTime(new Date())
                .build();
    }

    public static BeanPostLogDTO buildPostLog(String applicationName) {
        return BeanPostLogDTO.builder()
                .applicationName(applicationName)
                .clientId(TenantContextHolder.getTenant())
                .operaId(UserContextHolder.getUserId())
                .operaName(UserContextHolder.getUserName())
                .ip(RequestContextHolder.get().getIp())
                .city(RequestContextHolder.get().getCity())
                .area(RequestContextHolder.get().getArea())
                .status("0")
                .operaTime(new Date())
                .build();
    }

    public static LoginLogDTO buildLoginLog(String applicationName) {
        return LoginLogDTO.builder()
                .applicationName(applicationName)
                .clientId(TenantContextHolder.getTenant())
                .operaId(UserContextHolder.getUserId())
                .operaName(UserContextHolder.getUserName())
                .ip(RequestContextHolder.get().getIp())
                .city(RequestContextHolder.get().getCity())
                .area(RequestContextHolder.get().getArea())
                .os(RequestContextHolder.get().getOs())
                .browser(RequestContextHolder.get().getBrowser())
                .status("0")
                .operaTime(new Date())
                .build();
    }

    public static MessageLogDTO buildMessageLog(String applicationName) {
        return MessageLogDTO.builder()
                .applicationName(applicationName)
                .clientId(TenantContextHolder.getTenant())
                .operaId(UserContextHolder.getUserId())
                .operaName(UserContextHolder.getUserName())
                .ip(RequestContextHolder.get().getIp())
                .city(RequestContextHolder.get().getCity())
                .area(RequestContextHolder.get().getArea())
                .status("0")
                .operaTime(new Date())
                .build();
    }
}